/// @tags:
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 5e3 + 5, mod = 1e9 + 7;

struct Edge {
  int v, nxt;
} e[N << 1];

int e_cnt;
int heads[N], val[N], fa[N];
LL f[N];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void solve(int u) {
  int tmp = fa[u];
  while (tmp != 0) {
    f[u] += (val[tmp] % val[u] == 0) ? f[tmp] : 0;
    if (f[u] >= mod) f[u] -= mod;
    tmp = fa[tmp];
  }
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if ((v = e[i].v) != fa[u]) {
      fa[v] = u;
      solve(v);
    }
  }
}

inline int main() {
  int n;
  cin >> n;
  for (int i = 1, u, v; i < n; ++i) cin >> u >> v, add(u, v), add(v, u);
  for (int i = 1; i <= n; ++i) cin >> val[i];
  f[1] = 1;
  solve(1);
  for (int i = 1; i <= n; ++i) cout << f[i] << '\n';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("walk.in", "r", stdin);
  freopen("walk.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
